package com.example.expenses;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;

public class AddExpenseDialog extends DialogFragment{
	
	private static final String TAG = "AddExpenseDialog";
	
	private EditText date;
	private EditText supplier;
	private EditText kind;
	private EditText subKind;
	private EditText price;
	private EditText name;
	private EditText comment;

	private int mNum;

	static AddExpenseDialog newInstance() {
        return new AddExpenseDialog();
    }

	 @Override
	    public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	       

	 }

	/*
	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		
		
		// Use the Builder class for convenient dialog construction
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setMessage(R.string.action_add_expense)
               .setPositiveButton(R.string.add_action, new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                	   ((MainActivity)getActivity()).addExpense();
                   }
               })
               .setNegativeButton(R.string.cancel_action, new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                       // User cancelled the dialog
                   }
               });
        // Inflate View
        //LayoutInflater inflator = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
       // View addExpenseView = inflator.inflate(R.layout.add_expense_layout, null);
       // builder.setView(addExpenseView);
        // Create the AlertDialog object and return it
        return builder.create();

	}*/
	
	 @Override
	    public View onCreateView(LayoutInflater inflater, ViewGroup container,
	            Bundle savedInstanceState) {
		 	View view = inflater.inflate(R.layout.add_expense_fragment, null);
		 	 date = (EditText)view.findViewById(R.id.dateedit);
		        if(date == null)
		        	Log.e(TAG,"nulllllllllllllllllllllll");
			    supplier = (EditText) view.findViewById(R.id.suplierEdit);
			    kind = (EditText) view.findViewById(R.id.kindEdit);
			    subKind = (EditText) view.findViewById(R.id.subKindEdit);
			    price = (EditText) view.findViewById(R.id.priceEdit);
			    name = (EditText) view.findViewById(R.id.nameEdit);
			    comment = (EditText) view.findViewById(R.id.commentEdit);
		 
		 return view;
	 }

	 protected void addExpense() {
	    	Bundle data = getData();
			Log.d(TAG,"Adding: "+
					"\n date: " + data.getString("date") +
					"\n supplier: " + data.getString("suplier") +
					"\n kind: " + data.getString("kind") +
					"\n subkind: " + data.getString("subkind") +
					"\n price: " + data.getString("price") +
					"\n name: " + data.getString("name") +
					"\n comment: " + data.getString("comment") 
					);
			
		}
	 private Bundle getData() {
			Bundle data = new Bundle();
			
			data.putString("date", date.getText().toString());
			data.putString("supplier", supplier.getText().toString());
			data.putString("kind", kind.getText().toString());
			data.putString("subkind", subKind.getText().toString());
			data.putString("name", name.getText().toString());
			data.putString("price", price.getText().toString());
			data.putString("comment", comment.getText().toString());
			return null;
		}

	

}
